/**
 * 
 */
var allCities;
var allCitiesReverse;

var busDetails;
var selectedBusDetails;

var selectedSource;
var selectedDestination;

function getDestinations(sourceid, cb){	
	url = 'index.php/redbus/getDestinations/';
	if (sourceid != null) url = url + sourceid;
	//if (sourceid != null) url = url+sourceid;
	$.ajax({url: url, success: function(data) {gotDestinations(data); cb(allCitiesReverse)}, dataType: 'json'})
	.error(function(data) { console.debug(data)});
}
  
function gotDestinations(data) {
	if (!allCities) { 
		allCities = {};
		allCitiesReverse = {};
		$.each(data, function(index, value) {
			value.value = value.value.toLowerCase();
			allCities[value.id] = value.value;
			allCitiesReverse[value.value] = value.id;
		});
	}
}

function parseNPopulate(data, input, changeCB) {
	var sources = new Array();
	$.each(data, function(index, value) {
		sources.push(index);
	});
    return $("input#"+input).autocomplete({
        source: sources,
        autoComplete: true,
        select: changeCB
    });		
}
